﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace LDSP.BRL
{
    public class BaseEnterpriseGroupAdminPage : BaseEnterpriseAdminPage
    {
        public override void RedirectBefore()
        {
            if (LoginUser == null || LoginUser.UserType != EnterpriseUserType.企业管理员 || LoginUser.Enterprise.IsEnterpriseGroup == false)
            {
                this.GoToLogin();
            }
            else
            {
                //用户被删除后，即使已登录了也退出
                LoginUser.GetProperties(LoginUser.ID);
                if (LoginUser.ID == 0)
                {
                    this.GoToLogin();
                }
            }
        }

        /// <summary>
        /// 是否允许系统管理员
        /// </summary>
        /// <param name="redirect">是否重定向到默认页</param>
        /// <returns></returns>
        protected override bool AllowEnterpriseUser(bool redirect = true)
        {
            if (LoginUser != null
                && LoginUser.UserType == EnterpriseUserType.企业管理员
                && LoginUser.Enterprise.IsEnterpriseGroup == true)
            {
                return true;
            }
            else
            {
                this.JSAlert("您没有访问权限！", true);
                if (redirect)
                {
                    this.JSRedirect("MyPage.aspx", false, true);
                }
                return false;
            }
        }
    }
}